﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Events.PersistentCallGroup
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using UnityEngine.Serialization;

#nullable disable
namespace UnityEngine.Events
{
  [Serializable]
  internal class PersistentCallGroup
  {
    [FormerlySerializedAs("m_Listeners")]
    [SerializeField]
    private List<PersistentCall> m_Calls;

    public PersistentCallGroup() => this.m_Calls = new List<PersistentCall>();

    public int Count => this.m_Calls.Count;

    public PersistentCall GetListener(int index) => this.m_Calls[index];

    public IEnumerable<PersistentCall> GetListeners() => (IEnumerable<PersistentCall>) this.m_Calls;

    public void AddListener() => this.m_Calls.Add(new PersistentCall());

    public void AddListener(PersistentCall call) => this.m_Calls.Add(call);

    public void RemoveListener(int index) => this.m_Calls.RemoveAt(index);

    public void Clear() => this.m_Calls.Clear();

    public void RegisterEventPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.EventDefined;
    }

    public void RegisterVoidPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.Void;
    }

    public void RegisterObjectPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      UnityEngine.Object argument,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.Object;
      listener.arguments.unityObjectArgument = argument;
    }

    public void RegisterIntPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      int argument,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.Int;
      listener.arguments.intArgument = argument;
    }

    public void RegisterFloatPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      float argument,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.Float;
      listener.arguments.floatArgument = argument;
    }

    public void RegisterStringPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      string argument,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.String;
      listener.arguments.stringArgument = argument;
    }

    public void RegisterBoolPersistentListener(
      int index,
      UnityEngine.Object targetObj,
      System.Type targetObjType,
      bool argument,
      string methodName)
    {
      PersistentCall listener = this.GetListener(index);
      listener.RegisterPersistentListener(targetObj, targetObjType, methodName);
      listener.mode = PersistentListenerMode.Bool;
      listener.arguments.boolArgument = argument;
    }

    public void UnregisterPersistentListener(int index)
    {
      this.GetListener(index).UnregisterPersistentListener();
    }

    public void RemoveListeners(UnityEngine.Object target, string methodName)
    {
      List<PersistentCall> persistentCallList = new List<PersistentCall>();
      for (int index = 0; index < this.m_Calls.Count; ++index)
      {
        if (this.m_Calls[index].target == target && this.m_Calls[index].methodName == methodName)
          persistentCallList.Add(this.m_Calls[index]);
      }
      this.m_Calls.RemoveAll(new Predicate<PersistentCall>(persistentCallList.Contains));
    }

    public void Initialize(InvokableCallList invokableList, UnityEventBase unityEventBase)
    {
      foreach (PersistentCall call in this.m_Calls)
      {
        if (call.IsValid())
        {
          BaseInvokableCall runtimeCall = call.GetRuntimeCall(unityEventBase);
          if (runtimeCall != null)
            invokableList.AddPersistentInvokableCall(runtimeCall);
        }
      }
    }
  }
}
